home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
011-020
/
amok19
/
smallinout
/
smallinout.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
2KB
|
100 lines
(*---------------------------------------------------------------------------
:Program. SmallInOut.mod
:Author. Fridtjof Siebert
:Address. Nobileweg 67, D-7-Stgt-40
:Phone. (0)711/822509
:Shortcut. [fbs]
:Version. 1.0
:Date. 15-May-89
:Copyright. PD
:Language. Modula-II
:Translator. M2Amiga v3.1d
:Contents. Small replacement of InOut
---------------------------------------------------------------------------*)
IMPLEMENTATION MODULE SmallInOut; (* $R- $S- $V- *)
FROM SYSTEM IMPORT ADR;
FROM Arts IMPORT wbStarted, Assert;
FROM ASCII IMPORT eof,lf;
IMPORT Dos;
VAR
out,in: Dos.FileHandlePtr;
l: LONGINT; (* dummy *)
PROCEDURE Length(s: ARRAY OF CHAR): LONGINT;
BEGIN l := 0; WHILE (l<=HIGH(s)) AND (s[l]#0C) DO INC(l) END; RETURN l;
END Length;
PROCEDURE Write(ch: CHAR);
BEGIN l := Dos.Write(out,ADR(ch),1) END Write;
PROCEDURE WriteLn;
BEGIN Write(12C) END WriteLn;
PROCEDURE WriteString(str: ARRAY OF CHAR);
BEGIN l := Dos.Write(out,ADR(str),Length(str)) END WriteString;
PROCEDURE WriteInt(x: LONGINT; n: INTEGER);
BEGIN
IF x<0 THEN Write("-"); x := -x; DEC(n) END;
IF n>1 THEN IF x>9 THEN WriteInt(x DIV 10,n-1); x := x MOD 10
ELSE WHILE n>1 DO Write(" "); DEC(n) END END;
END;
Write(CHAR(x+ORD("0")));
END WriteInt;
PROCEDURE WriteHex(x: LONGINT; n: INTEGER);
BEGIN
IF x<0 THEN Write("-"); x := -x; DEC(n) END;
IF n>1 THEN WriteHex(x DIV 16,n-1); x := x MOD 16 END;
IF x>9 THEN Write(CHAR(x+55)) ELSE Write(CHAR(x+ORD("0"))) END;
END WriteHex;
PROCEDURE Read(VAR ch: CHAR);
BEGIN IF Dos.Read(in,ADR(ch),1)#1 THEN ch := eof END;
END Read;
PROCEDURE ReadString(VAR str: ARRAY OF CHAR);
VAR i: LONGINT;
BEGIN
i := 0;
REPEAT
Read(str[i]);
IF str[i]=lf THEN str[i] := 0C; RETURN END;
INC(i);
UNTIL i=HIGH(str);
END ReadString;
PROCEDURE ReadLongInt(VAR x: LONGINT);
VAR
ch: CHAR;
d: INTEGER;
neg: BOOLEAN;
BEGIN
x := 0;
neg := FALSE;
WHILE (ch#lf) AND (ch#eof) AND (ch#0C) DO
IF ch="-" THEN neg := TRUE;
ELSIF (ch>="0") AND (ch<="9") THEN
d := ORD(ch)-ORD("0");
IF (MAX(LONGINT)-d) DIV 10 >= x THEN x := 10*x+d END;
END;
Read(ch);
END;
IF neg THEN x := -x END;
END ReadLongInt;
PROCEDURE ReadInt(VAR x: INTEGER);
BEGIN
ReadLongInt(l);
x := l REM 32768;
END ReadInt;
BEGIN
Assert(NOT wbStarted,ADR("Use CLI!"));
out := Dos.Output(); in := Dos.Input();
END SmallInOut.